<?php
/**
 * PHP Daycare
 * This file will process the login info.
 * @author Jason Butz
 * @version 0.0
 * @package PHPDaycare
 */

include_once("functions.php");
include_once("config.php");
session_start();
// Our user must be logged in to view things, otherwise they get a login screen!
if($session->isloggedin())
{
	// The user is logged in. Then we don't need to be here!
	header("Location: index.php");
}
else
{
	// I guess we need to log the user in, then send them elsewhere
	$u = mysql_real_escape_string($_POST['username']);
	$p = mysql_real_escape_string($_POST['password']);
	// Check to see if they are in the database and the credentials match
	$r = $db->query("SELECT ID FROM worker  WHERE username='$u' AND password=password('$p');");
	if($row = mysql_fetch_array($r))
	{
		// They can now login!
		$session->session_setup($u, $p);
		$log->login($u);
		header("Location: index.php");
	}
	else
	{
		// They messed up... wrong password or something!
		$log->loginFailW($u);
		$html = "<p><b>Error:</b> The username and password provided were not valid. Please <a href=\"index.php\">try again</a>.</p>";
		$temp->displayCont($html,TRUE);
	}
}
?>

